package ext.opensource.netty.common.utils;

import java.util.concurrent.atomic.AtomicInteger;

public class MessageId {

	private static AtomicInteger index = new AtomicInteger(10);

	/**
	 * 获取messageId
	 * 
	 * @return id
	 */
	public static int messageId() {
		for (;;) {
			final int current = MessageId.index.get();
			final int next = (current >= Integer.MAX_VALUE ? 0 : current + 1);
			if (MessageId.index.compareAndSet(current, next)) {
				return current;
			}
		}
	}
}
